﻿using System;
using System.Collections.Generic;
using System.Text;

namespace StudentManagement.Tools
{
    public class StringTransition
    {
        /// <summary>
        /// 截取字符串
        /// </summary>
        /// <param name="str">需要截取的字符串</param>
        /// <param name="length">截取字符长度</param>
        /// <returns></returns>
        public static string Intercept(string str, int length)
        {
            return str.Substring(0, str.Length > length ? length : str.Length);
        }

        /// <summary>
        /// 去除尾部字符串
        /// </summary>
        /// <param name="str">需要去除的字符串</param>
        /// <param name="endStr">尾部字符串</param>
        /// <returns></returns>
        public static string TrimEnd(string str, string endStr)
        {
            if (str.Length < endStr.Length) return str;
            return str.EndsWith(endStr) ? str.Substring(0, str.Length - endStr.Length) : str;
        }
    }
}
